package bishi.tengxun.secondary;

/**
 * @author: 唐小尊
 * @email: 1171702529@qq.com
 * @cate: 2021/09/05 18:47
 */
public class one {
    public static class ListNode {
        int val;
        ListNode next;

        ListNode(int x) {
            val = x;
        }
    }

    public static void main(String[] args) {
        one o = new one();
        ListNode node1 = new ListNode(1);
        node1.next = new ListNode(2);
        node1.next.next = new ListNode(3);


        ListNode node2 = new ListNode(4);
        node2.next = new ListNode(5);

        ListNode node3 = new ListNode(7);
        node3.next = new ListNode(8);
        node3.next.next = new ListNode(9);
        node3.next.next.next = new ListNode(10);
        node3.next.next.next.next = new ListNode(11);
        node3.next.next.next.next.next = new ListNode(12);


        ListNode solve = o.solve(new ListNode[]{node1, node2, node3});
        while (solve != null) {
            System.out.println(solve.val);
            solve = solve.next;
        }
    }

    public ListNode solve(ListNode[] a) {
        ListNode res = new ListNode(-1);
        ListNode deep = res;
        boolean p = true;
        while (p) {
            p = false;
            for (int i=0;i<a.length;i++){
                if (a[i] == null) continue;
                p = true;
                deep.next = new ListNode(a[i].val);
                deep = deep.next;
                a[i] = a[i].next;
            }
        }
        return res.next;
    }
}
